home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / cuj0796.zip / BELL.ZIP / TEST.C < prev   
Text File  |  1996-04-23  |  1KB  |  48 lines

  1. /*   Listing 2
  2.  
  3.      Test driver for forfun().
  4. */
  5.  
  6. #include <stdio.h>
  7. #define MAXNUMLOOPS 10
  8.  
  9. void forfun (int *, int *, int *, int , int);
  10. void work(int *, int);
  11.  
  12. main()
  13. {
  14. int r[MAXNUMLOOPS], startval[MAXNUMLOOPS], endval[MAXNUMLOOPS],
  15.      lastloopsub;
  16.  
  17. /*  Specify test data  */
  18. /*  Must have  0 <= lastloopsub <= MAXNUMLOOPS - 1  */
  19. lastloopsub = 2;
  20.  
  21. startval[0] = 0;
  22. startval[1] = 1;
  23. startval[2] = 5;
  24. endval[0] = 2;
  25. endval[1] = 4;
  26. endval[2] = 7;
  27. /*  End of test data specification */
  28.  
  29. /*  Explicitly nested for statements */
  30. for (r[0] = startval[0]; r[0] <= endval[0]; r[0]++)
  31. for (r[1] = startval[1]; r[1] <= endval[1]; r[1]++)
  32. for (r[2] = startval[2]; r[2] <= endval[2]; r[2]++)
  33.      work(r, lastloopsub);
  34.  
  35. /*  Recursively nested for statements  */
  36. forfun (r, startval, endval, 0, lastloopsub);
  37.  
  38. exit (0);
  39. }  /*  end of  main()  */
  40.  
  41. void work(int * r, int lastloopsub)
  42. {
  43. int loop;
  44. for (loop = 0; loop <= lastloopsub; loop++)
  45.       printf("r[%d] = %d ", loop, r[loop]);
  46. printf("\n");
  47. }  /*  end of work()  */
  48.